package org.mspring.mlog.dao.impl;

import java.io.Serializable;
import java.sql.SQLException;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mspring.mlog.dao.BaseDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

/**
 * DAO基类。
 * @author fairchildy
 * @param <T>
 */
@Repository
public abstract class BaseDaoImpl<T extends Serializable> implements BaseDao<T> {
	protected Logger log = LoggerFactory.getLogger(getClass());

	@Resource
	private SqlSessionFactory sessionFactory;
	

	public SqlSessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public SqlSession getSqlSession(){
		
		SqlSession sqlSession = getSessionFactory().openSession();
		try {
			sqlSession.getConnection().setAutoCommit(false);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return  sqlSession;
	}

}
